
//player globalChat format[" PARAM : %1",_this select 0];

_clickPos=_this select 0;

//_civil=_clickPos nearestObject "Civilian";

RespawnTrigger setPos _clickPos;
sleep 0.2;
_civil=((list RespawnTrigger) select 0);
format[" PARAM : %1",(list RespawnTrigger)]  call debug;

for [{_c=0},{_c<(count CivilsDetectingHumans)},{_c=_c+1}]  do
{
		scopeName "civilLoop";
		
		if(_civil in ((CivilsDetectingHumans select _c) select 1))then
		{
			CurrentCivil=_civil;
			// civil found so respawn in it !
			IsIntoACivil=true;
			
			// remove map click action
			//onMapSingleClick "";
			
            format[" Teleport : %1",_civil] call debug;
            _civilPos=getPos _civil;
            _civilDir=getDir _civil;

            // camera effect
            _camera = "camera" camCreate [0,0,200];

            _camera camSetPos [(_civilPos select 0)+10,(_civilPos select 1)+10,(_civilPos select 2)+10];
            _camera camSetTarget [(_civilPos select 0),(_civilPos select 1),(_civilPos select 2)+1.5];

            _camera camSetFov 0.700;
            _camera cameraEffect ["internal","back"];
            _camera camCommit 0;
			
			openMap [false, false];
			
            waitUntil { camCommitted _camera };

            _camera camSetFov 0.50;
            _camera camCommit 5;

            sleep 2;
            
            _civilPos=getPos _civil;    
            
            // replace the camera if the civil moved during the cutscene
            _camera camSetTarget [(_civilPos select 0),(_civilPos select 1),(_civilPos select 2)+1.5];
            _camera camCommit 2;

            _civil setPos [(_civilPos select 0)+100,(_civilPos select 1)+100,0];   

            player setPos _civilPos;
            player setDir _civilDir;

            waitUntil { camCommitted _camera };

            player cameraEffect["terminate","back"];
            camDestroy _camera;
			
			
			
            // wait until the agent died
            waitUntil{ !(alive player) or (CurrentCivil!=_civil) };
			
			sleep 0.2;
			
			// if the agent change civil
			if(CurrentCivil!=_civil)then{
				// replace the agent by the civil
				_civil setPos (getPos player);
				breakOut "civilLoop";
			};
			

            _finalPosPlayer=(getPos player);
            _finalDirPlayer=(getDir player);

 
            player setPos [0,0,0];
            // replace the civil body in the place where the agent were killed
            _civil switchMove "FXStandDip";
            _civil setDamage 1;

            _civil setdir _finalDirPlayer;
            _civil setPos _finalPosPlayer;

            waitUntil{ (alive player) }; // wait for the agent to respawn

            sleep 60;
            deleteVehicle _civil;
			
			breakOut "civilLoop";
			
		};
};

deleteVehicle _trg;

//if(_civil in CivilsDetectingHumans) then {
    
  

    

//};